package com.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dao.BusinessStaffDAO;
import com.pojo.BusinessStaff;
import com.util.ValidateHelper;
import com.vo.BusinessStaffVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BusinessStaffService extends ServiceImpl<BusinessStaffDAO, BusinessStaff> {
    @Autowired
    private BusinessStaffDAO businessStaffDAO;

    public IPage<BusinessStaffVo> getBusinessStaffList(String name, String businessId, String qyId, Integer status, Integer page, Integer limit) {
        if (ValidateHelper.isEmptyString(name)) {
            name = null;
        }
        if (ValidateHelper.isEmptyString(businessId)) {
            businessId = null;
        }
        if (ValidateHelper.isEmptyString(qyId)) {
            qyId = null;
        }
        Page p = new Page(page, limit);

        IPage<BusinessStaffVo> iPage = businessStaffDAO.selectBusinessStaff(p,name, businessId, qyId, status) ;
        return iPage;
    }

    /*public int selectBh(String bh){
        return businessStaffDAO.selectList(new QueryWrapper<BusinessStaff>().eq("bh", bh)).size();
    }

    public int selectBhId(String bh, String id){
        return businessStaffDAO.selectList(new QueryWrapper<BusinessStaff>().eq("bh", bh).eq("id", id)).size();
    }

    */
    /**
     * 根据员工编号获取商户员工信息
     * @return
     *//*
    public BusinessStaff getBusinessStaffByStaffBh (String staffBh) {
        QueryWrapper query = new QueryWrapper();
        query.eq("bh", staffBh);
        query.last("limit 1");
        return businessStaffDAO.selectOne(query);
    }*/


    /**
     * 根据商户ID获取商户员工列表
     * @param businessId
     * @return
     */
    public IPage<BusinessStaff> getBusinessStaffListByApp (String businessId, Integer page, Integer limit) {
        IPage p = new Page(page, limit);
        QueryWrapper query = new QueryWrapper();
        query.eq("businessId", businessId);
        query.orderByDesc("create_time");
        return businessStaffDAO.selectPage(p, query);
    }

    /**
     * 根据员工ID获取商户员工
     * @param staffId
     * @return
     */
    public BusinessStaff getBusinessStaffByStaffId (String staffId) {
        QueryWrapper query = new QueryWrapper();
        query.eq("staffId", staffId);
        query.last("limit 1");
        return businessStaffDAO.selectOne(query);
    }

}
